package com.ktgj.service.service.impl;

import com.ktgj.common.core.utils.DateUtils;
import com.ktgj.service.domain.AirportService;
import com.ktgj.service.domain.ContractLinkAirportservice;
import com.ktgj.service.domain.ContractLinkAirportservicePrice;
import com.ktgj.service.mapper.AirportServiceMapper;
import com.ktgj.service.mapper.ContractLinkAirportserviceMapper;
import com.ktgj.service.mapper.ContractLinkAirportservicePriceMapper;
import com.ktgj.service.service.IAirportServiceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 机场服务			
Service业务层处理
 * 
 * @author ruoyi
 * @date 2021-09-03
 */
@Service
@Transactional
public class AirportServiceServiceImpl implements IAirportServiceService 
{
    @Autowired
    private AirportServiceMapper airportServiceMapper;

    //机场服务合同中间表
    @Autowired
    private ContractLinkAirportserviceMapper contractLinkAirportserviceMapper;

    //机场服务合同价格
    @Autowired
    private ContractLinkAirportservicePriceMapper contractLinkAirportservicePriceMapper;
    /**
     * 查询机场服务			

     * 
     * @param airportServiceId 机场服务			
ID
     * @return 机场服务			

     */
    @Override
    public AirportService selectAirportServiceById(Long airportServiceId)
    {
        return airportServiceMapper.selectAirportServiceById(airportServiceId);
    }

    /**
     * 查询机场服务			
列表
     * 
     * @param airportService 机场服务			

     * @return 机场服务			

     */
    @Override
    public List<AirportService> selectAirportServiceList(AirportService airportService)
    {
        return airportServiceMapper.selectAirportServiceList(airportService);
    }

    /**
     * 新增机场服务			

     * 
     * @param airportService 机场服务			

     * @return 结果
     */
    @Override
    public int insertAirportService(AirportService airportService)
    {
        airportService.setCreateTime(DateUtils.getNowDate());
        return airportServiceMapper.insertAirportService(airportService);
    }

    /**
     * 修改机场服务			

     * 
     * @param airportService 机场服务			

     * @return 结果
     */
    @Override
    public int updateAirportService(AirportService airportService)
    {
        airportService.setUpdateTime(DateUtils.getNowDate());
        return airportServiceMapper.updateAirportService(airportService);
    }

    /**
     * 批量删除机场服务			

     * 
     * @param airportServiceIds 需要删除的机场服务			
ID
     * @return 结果
     */
    @Override
    public int deleteAirportServiceByIds(Long[] airportServiceIds)
    {
        return airportServiceMapper.deleteAirportServiceByIds(airportServiceIds);
    }

    /**
     * 删除机场服务			
信息
     * 
     * @param airportServiceId 机场服务			
ID
     * @return 结果
     */
    @Override
    public int deleteAirportServiceById(Long airportServiceId)
    {
        return airportServiceMapper.deleteAirportServiceById(airportServiceId);
    }

    /**
     * 新增机场合同中间表、价格表数据
     * @param airportservice 对象
     * @return
     */
    @Override
    public boolean addAirportServicePrice(ContractLinkAirportservice airportservice) {
        boolean flag = false;
        int count = 0;
        airportservice.setCraeteTime(DateUtils.getNowDate());
        int result = contractLinkAirportserviceMapper.insertContractLinkAirportservice(airportservice);
        if(result > 0){
            //获取新增后的主键
            Long contractAirportServiceId = airportservice.getContractAirportServiceId();
            List<ContractLinkAirportservicePrice> priceList = airportservice.getPriceList();
            for (ContractLinkAirportservicePrice airportservicePrice : priceList) {
                        //封装数据
                ContractLinkAirportservicePrice price = new ContractLinkAirportservicePrice();
                price.setContractAirportServiceId(contractAirportServiceId);
                price.setDayId(airportservicePrice.getDayId());
                price.setBasePrice(airportservicePrice.getBasePrice());
                price.setSalePrice(airportservicePrice.getSalePrice());
                price.setRecommendedRetailPrice(airportservicePrice.getRecommendedRetailPrice());
                price.setPointsConversionRatio(airportservicePrice.getPointsConversionRatio());
                price.setPointsCashToCredit(airportservicePrice.getPointsCashToCredit());
                price.setPointsCost(airportservicePrice.getPointsCost());
                price.setStatus(airportservice.getStatus());
                price.setOpemployeeId(airportservice.getOpemployeeId());
                price.setUpdateTime(airportservice.getUpdateTime());
                price.setMemberPrice(airportservicePrice.getMemberPrice());
                price.setCreateTime(DateUtils.getNowDate());

                //执行机场合同价格维护
                count= contractLinkAirportservicePriceMapper.insertContractLinkAirportservicePrice(price);
            }
        }
        if(count > 0){
            flag =true;
        }
        return flag;
    }

    @Override
    public int selectAirportPrice(Long contractId, Long serviceId) {
        return contractLinkAirportserviceMapper.selectAirportPrice(contractId,serviceId);
    }

    @Override
    public List<AirportService> getAirportServiceList() {
        return airportServiceMapper.getAll();
    }
}
